#include "spi.h"

void spi2_init(void)
{
    // 错误类型返回值
    esp_err_t ret;
    // spi初始化结构体
    spi_bus_config_t spi_bus_conf = {0};

    /* SPI总线配置 */
    spi_bus_conf.miso_io_num = SPI_MISO_GPIO_PIN;                                   /* SPI_MISO引脚 */
    spi_bus_conf.mosi_io_num = SPI_MOSI_GPIO_PIN;                                   /* SPI_MOSI引脚 */
    spi_bus_conf.sclk_io_num = SPI_CLK_GPIO_PIN;                                    /* SPI_SCLK引脚 */
    spi_bus_conf.quadwp_io_num = -1;                                                /* SPI写保护信号引脚，该引脚未使能 */
    spi_bus_conf.quadhd_io_num = -1;                                                /* SPI保持信号引脚，该引脚未使能 */
    spi_bus_conf.max_transfer_sz = 32;                                              /* 配置最大传输大小，以字节为单位 */
    
    /* 初始化SPI总线 */
    ret=spi_bus_initialize(SPI2_HOST, &spi_bus_conf, SPI_DMA_CH_AUTO);
    if (ret != ESP_OK) {
        ESP_LOGE("SPI", "SPI设备初始化失败: %s", esp_err_to_name(ret));
        return;
    }
}